/**
 * file
 */
package com.tdkj.action.front.member.risevalue;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.opensymphony.xwork2.ActionContext;
import com.tdkj.action.BaseAction;
import com.tdkj.model.decorate.BeanDiamond;
import com.tdkj.model.decorate.BeanDiamondCustom;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.ServiceException;
import com.tdkj.service.decorate.IBeanDiamondCustomBuyService;
import com.tdkj.service.decorate.IBeanDiamondCustomService;
import com.tdkj.service.decorate.IBeanDiamondService;
import com.tdkj.util.Page;
import com.tdkj.util.PublicConfing;

public class DiamondAction extends BaseAction {
	
	private BeanDiamondCustom custom;
	
	private IBeanDiamondCustomService diamondCustomService;
	
	private IBeanDiamondService diamondService;
	
	private IBeanDiamondCustomBuyService diamondCustomBuyService;
	
	public String execute(){
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		
		String hqlDiamonds = " from " +BeanDiamond.class.getName() + " as bean order by bean.name asc";
		Query queryDiamonds = this.createQuery(hqlDiamonds);
		Page diamonds = this.getBaseService().getBaseDao().findBy(queryDiamonds, 1, 10);
		this.getReturnInfo().put("diamonds", diamonds);
		
		
		String hqlBuys = " from " +BeanDiamond.class.getName() + " as bean order by bean.name asc";
		Query queryBuys = this.createQuery(hqlBuys);
		this.queryByPage(queryBuys, "diamondAction.action", 10);
		
		return "success";
	}
	
	public String buy() throws ServiceException{
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		
		diamondCustomBuyService.create(userId, custom.getId());
		
		return execute();
	}


	@Resource
	public void setDiamondCustomService(
			IBeanDiamondCustomService diamondCustomService) {
		this.diamondCustomService = diamondCustomService;
	}

	@Resource
	public void setDiamondService(IBeanDiamondService diamondService) {
		this.diamondService = diamondService;
	}

	public BeanDiamondCustom getCustom() {
		return custom;
	}

	public void setCustom(BeanDiamondCustom custom) {
		this.custom = custom;
	}

	@Resource
	public void setDiamondCustomBuyService(
			IBeanDiamondCustomBuyService diamondCustomBuyService) {
		this.diamondCustomBuyService = diamondCustomBuyService;
	}
	
}
